library(ggplot2)
#library(export)

setwd("C:\\Users\\dell\\Desktop\\2022-08-two-speed")
data <- read.csv("JSFIR_fused.csv",header = T)

P <- ggplot(data, aes(x=log10(data$fiveprime), y=log10(data$threeprime)))
P + 
  geom_bin2d(bins=40) + geom_hex(bins=40) +
#  scale_fill_gradient(low="lightblue", high="red") + 
#  scale_colour_gradient2(low = "red",mid = "white",high = "blue") + 
  #自定义的n色梯度
  scale_fill_gradientn(colours = c("white","WhiteSmoke","lightgrey", "grey", "lightblue", "lightskyblue", 
                                    "Yellow", "orange", "OrangeRed", "red")) +
#  scale_fill_continuous(type = c("viridis")) + 
  theme_bw() +
  xlab("5' intergenic") + ylab("3' intergenic") +
  labs(fill="Level") + theme(legend.title=element_text(size=8,face="bold")) +
  theme(plot.title = element_text(size = 14, face="bold"), 
      text = element_text(size = 12), 
      axis.title = element_text(face="bold"), 
      axis.text.x=element_text(size = 10))

P + stat_density_2d(aes(fill = ..level..), geom = "polygon", colour="white")

## 添加数据点

ggplot(data= rxlrData,
       aes(x= rxlrData$fiveprime, y= rxlrData$threeprime, 
           geom="blank")) +
  annotation_custom(g, xmin=-Inf, xmax=Inf, ymin= -Inf,
                    ymax=Inf) +
  coord_fixed(ratio=1) +
  geom_point(shape=20,
             size=3.5, alpha=0.7, na.rm=FALSE) +
  
  #  facet_grid(rows = 1,cols = 2) +
  #  facet_wrap(vars(Chrid), nrow = 3) + 
  scale_y_log10(breaks = BinLimits[2:length(BinLimits)],
                limits = c(BinLimits[2], BinLimits[NumBins +1])) +
  scale_x_log10(breaks= BinLimits [2:length(BinLimits)],
                limits=c(BinLimits[2], BinLimits[NumBins +1])) +
  theme(axis.text.y=element_text(size = 10, vjust=0.5)) + theme(axis.text.x=element_text(size=10, vjust=0.5,
                                                                                         angle=90)) +
  theme(axis.title.x = element_text(face="bold",size=12)) +
  xlab("five prime intergenic region") +
  theme(axis.title.y = element_text(face="bold",size=12)) + 
  ylab("three prime intergenic region") +
  scale_color_manual(values = c("black", "purple")) +
  theme_bw()